package com.jason.apps.fromdashboard;

import java.util.ArrayList;
import java.util.HashMap;

import com.apps.realtyportal.R;
import com.forimageandlist.ImageLoader;
import com.jason.apps.fromdashboard.MyProperty.MyOnClickSelectedListener;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MyAdapter extends BaseAdapter{

	private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    HashMap<String, String> property = new HashMap<String, String>();
    MyOnClickSelectedListener mCallback;
    
    
    public MyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        
        mCallback = (MyOnClickSelectedListener) activity;
     
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }


    @SuppressLint("ParserError")
	public View getView(final int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView name = (TextView)vi.findViewById(R.id.title); 
        TextView type = (TextView)vi.findViewById(R.id.contact); 
        TextView address = (TextView)vi.findViewById(R.id.artist); 
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
        
        
        
        property=data.get(position);
        
        name.setText(property.get("property_name"));
        type.setText(property.get("type"));
        address.setText(property.get("price"));
        
        imageLoader.DisplayImage(property.get("image"), thumb_image);
        
        vi.setOnClickListener(new OnClickListener() {
			
		
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mCallback.MyonArticleSelected(v,position);
				//Toast.makeText(activity, "Click here", Toast.LENGTH_LONG).show();
			}
		});
        return vi;

}

    
}
